<?php

namespace app\admin\library;

use think\Db;

class Works {

    public static function make($order_id){
        $works = Db::name('WorksCatalog')->where('order_id',$order_id)->find();
        if(empty($works)){
            $order = Db::name('ShoproOrderItem')->where('order_id',$order_id)->find();
            $goods = Db::name('shoproGoods')->where('id',$order['goods_id'])->find();
            $formwork = Db::name('Formwork')->where('id',$goods['formwork_id'])->find();
            $works = \app\admin\model\WorksCatalog::create([
                'user_id'=>$order['user_id'],
                'goods_id'=>$order['goods_id'],
                'description'=>$formwork['title'],
                'formwork_id'=>$goods['formwork_id'],
                'category_id'=>$formwork['category_id'],
                'title'=>$formwork['title'],
                'image'=>$formwork['image'],
                'order_id'=>$order_id,
                'photo_min'=>$formwork['photo_min'],
                'photo_max'=>$formwork['photo_max']
            ],true);
        }
    }
}